package test.尾递归优化

fun main(args: Array<String>) {
    val result = sum(100000)
    println(result)
}

tailrec fun sum(n: Int, result: Int = 0): Int {
    if (n == 1) {
        return result +1
    } else {
        return sum(n - 1, result + n)//调用自身之后做了其他操作
    }
}